package com.itxiao.controller;

import com.itxiao.annotation.Token;
import com.itxiao.config.SystemConfig;
import com.itxiao.pojo.dto.AddAddressDto;
import com.itxiao.pojo.dto.AddCartDto;
import com.itxiao.pojo.dto.UpdateCartDto;
import com.itxiao.pojo.vo.R;
import com.itxiao.service.CartItemService;
import com.itxiao.service.UserAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * (UserAddress)表控制层
 *
 * @author makejava
 * @since 2025-10-12 17:16:47
 */
@RestController
@RequestMapping("admin/api/v1/address")
@Api(tags = "收货地址模块")
@CrossOrigin
public class UserAddressController  {
    /**
     * 服务对象
     */
    @Resource
    private UserAddressService userAddressService;

    @ApiOperation("查询")
    @PostMapping("/list")
    @Token
    public R queryList(HttpServletRequest request) {
        return userAddressService.queryList(request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    @ApiOperation("查询默认")
    @GetMapping("/query-default")
    @Token
    public R queryDefault(HttpServletRequest request) {
        return userAddressService.queryDefault(request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @ApiOperation("新增或者修改")
    @PostMapping("/addOrUpdate")
    @Token
    public R addOrUpdate(@RequestBody AddAddressDto dto, HttpServletRequest request) {
        return userAddressService.addOrUpdate(dto,request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    @ApiOperation("设置默认")
    @PostMapping("/update")
    @Token
    public R updateIsDefault(@RequestBody AddAddressDto dto, HttpServletRequest request) {
        return userAddressService.updateIsDefault(dto,request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    @ApiOperation("删除地址")
    @DeleteMapping("/delete/{id}")
    @Token
    public R deleteById(@PathVariable Integer id) {
        return R.ok(userAddressService.removeById(id));
    }

}

